Skip to content

Harden radio save_other_choice lookup for JSON fields#382

Open
meravi wants to merge 2 commits into
WordPress:trunkfrom
meravi:fix/radio-save-other-choice-guards
Open

Harden radio save_other_choice lookup for JSON fields#382
meravi wants to merge 2 commits into
WordPress:trunkfrom
meravi:fix/radio-save-other-choice-guards

Conversation

@meravi

@meravi meravi commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Summary

This hardens acf_field_radio::update_value() when save_other_choice is enabled and the runtime field is JSON-only or missing identifiers.

Changes

  • Guard selector resolution (ID -> key -> bail early).
  • Bail if acf_get_field() fails or returns a field without DB ID.
  • Normalize choices to an array before appending custom values.
  • Add regression tests for JSON-only/missing-identifier edge cases.

Tests

  • Added:
    • test_update_value_save_other_choice_handles_json_field_without_id
    • test_update_value_save_other_choice_handles_missing_field_identifier

Fixes #381

@github-actions

github-actions Bot commented Mar 10, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ravikhadka, cbravobernal.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@cbravobernal cbravobernal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally:

  • The two new tests reproduce the reported warning against current trunk (Undefined array key "ID" in class-acf-field-radio.php:347) and pass with this fix.
  • Full PHPUnit suite (2230 tests), PHPStan, and phpcs all green on this branch.

The defensive selector build (ID → key → bail) and the acf_get_field() return check both look right, and behavior for valid persisted fields is unchanged.

Verification run via Claude Code, reviewed by @cbravobernal.

@cbravobernal cbravobernal force-pushed the fix/radio-save-other-choice-guards branch from 60fac64 to 7e8ff26 Compare June 10, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Radio save_other_choice triggers warnings for JSON-only or unidentified fields

2 participants